import '../public.dart';
import 'base_model.dart';

/// 章节信息
class ChapterImageModel extends BaseModel {
  /// 章节id
  int chapterId;

  ///  图片在本章节中的序号
  int index;

  ///  加载时的链接
  String originUrl;

  ///  图片原始宽度
  double originWidth;

  ///  图片原始高度
  double originHeight;

  ///  图片展示宽度
  double showWidth;

  ///  图片展示高度
  double showHeight;

  ///  是否初始化过
  bool isInited;

  ///  是否加载成功
  bool isSucceed;

  ///  加载失败次数
  int faileCount;

  ///  图片缓存
  ImageInfo dom;

  ///  数字越大，越优先加载
  int priority;

  ///  图片偏移值（横向为图片宽度，竖向为高度）结束量
  double endDistance;

  /// 是否完成了视窗检测
  bool isObserved;

  ///  是否生成了dom节点
  bool isCreateDom;

  ///  是否是当前章节最后一张图
  bool isLast;

  ///  插槽数据
  List<ChapterSlotModel> slots;

  /// 是否上锁
  // bool isLock;

  ///  是否发送czzz事件
  // bool isPushCnzz;

  ChapterImageModel.fromJson(Map<String, dynamic> data);

  ChapterImageModel.fromModel(int cid, String url, int imgIndex, bool last) {
    chapterId = cid;
    index = imgIndex;
    originUrl = url;
    isLast = last;
    originWidth = 0;
    originHeight = 0;
    showWidth = 0;
    showHeight = 0;
    isInited = false;
    isSucceed = false;
    faileCount = 0;
    priority = 0;
    endDistance = 0;
    isObserved = false;
    isCreateDom = false;
    slots = [];
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      'chapterId': chapterId,
      'index': index,
      'originUrl': originUrl,
      'originWidth': originWidth,
      'originHeight': originHeight,
      'showWidth': showWidth,
      'showHeight': showHeight,
      'isInited': isInited,
      'isSucceed': isSucceed,
      'faileCount': faileCount,
      'priority': priority,
      'endDistance': endDistance,
      'isObserved': isObserved,
      'isCreateDom': isCreateDom,
      'isLast': isLast,
      'slots': slots
    };
  }
}
